package com.wanxi.test;

import com.wanxi.uitl.IOTool;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class CopyFile {
    public static void main(String[] args) {
        /**
         * 1.源文件
         * 2.新路径
         * 3.复制文件：将旧文件里面的内容全部读取出来，然后写入到另一个文件
         */
        String oldPath = "E:\\wanxi\\canyin02-20230213\\day19IO流\\src\\com\\wanxi\\test\\aaa\\3.jpg";
        String path = "E:\\wanxi\\canyin02-20230213\\day19IO流\\src\\com\\wanxi\\test\\bbb";
        String fileName = "5.jpg";
        File file = IOTool.createFile(path, fileName);
        try {
//            读
            InputStream inputStream = new FileInputStream(oldPath);
//            写
            OutputStream outputStream = new FileOutputStream(file);
//            读取数据时，一个字节一个字节读，只要读取完后，则返回-1；
            int aa = 0;
            byte[] bytes = new byte[1024];
            while ((aa = inputStream.read(bytes)) != -1) {
//                System.out.println(aa);
//                outputStream.write("a".getBytes(StandardCharsets.UTF_8));
                outputStream.write(bytes, 0, aa);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
